#sqlalchemy :基于ORM的mysql库
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker,scoped_session

host = '127.0.0.1'
port = '3306'
db_user = 'root'
db_password = '123456'
db = 'hdc'#指定的数据库名称

#数据库连接字符串
SQLALCHEMY_DATABASE_URL = 'mysql+pymysql://'+db_user+':'+db_password+'@'+host+':'+port+'/'+db
#创建SQLAlchemy engine
engine = create_engine(
    SQLALCHEMY_DATABASE_URL,encoding='utf8',echo=True
)
#创建SessionLocl实例
SessionLocal = sessionmaker(autocommit=True,autoflush=True,bind=engine)
#scoped_session主要目的是为了线程安全
db_session = scoped_session(SessionLocal)

#创建模型类的基类
Base = declarative_base()
